package io.plus.server;

import io.plus.interactive.AsynchronousSocketChannelContext;
import io.plus.interactive.Configuration;
import io.plus.interactive.Node;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousSocketChannel;

public class ServerAsynchronousSocketChannelContext extends AsynchronousSocketChannelContext {

    public ServerAsynchronousSocketChannelContext(Configuration configuration, AsynchronousSocketChannel asynchronousSocketChannel) {
        super(configuration, asynchronousSocketChannel);
    }

    @Override
    public Node createClientNode(AsynchronousSocketChannel asynchronousSocketChannel) throws IOException {
        InetSocketAddress inetSocketAddress = (InetSocketAddress) asynchronousSocketChannel.getRemoteAddress();
        Node clientNode = new Node(inetSocketAddress.getHostString(), inetSocketAddress.getPort());
        return clientNode;
    }

    @Override
    public boolean isServer() {
        return true;
    }

}
